package com.imooc.security.data.pojo.response;

import com.imooc.security.data.pojo.exception.CommonException;

import java.util.Date;

/**
 * Common response DTO.
 *
 * @author Created By Houce
 */
public class CommonResponseDto<T> implements CommonResponse<T> {

    private static final long serialVersionUID = 1L;

    private String code;

    private String message;

    private Date time = new Date();

    private T body;

    /**
     * default constructor
     */
    public CommonResponseDto() {

    }

    /**
     * @param response returned body
     */
    public CommonResponseDto(final CommonResponse<T> response) {

        this.code = response.getCode();
        this.message = response.getMessage();
        this.body = response.getBody();
    }

    /**
     * @param response CommonResponse
     * @param body     returned body
     */
    public CommonResponseDto(final CommonResponse response, final T body) {

        this.code = response.getCode();
        this.message = response.getMessage();
        this.body = body;
    }

    /**
     * @param code    error code
     * @param message error message
     */
    public CommonResponseDto(final String code, final String message) {

        this.code = code;
        this.message = message;
    }

    /**
     * @param code    error code
     * @param message error message
     * @param body    returned body
     */
    public CommonResponseDto(final String code, final String message, final T body) {

        super();
        this.code = code;
        this.message = message;
        this.body = body;
    }

    /**
     * @param e CommonException
     */
    public CommonResponseDto(final CommonException e) {

        this.code = e.getCode();
        this.message = e.getMessage();
    }

    @Override
    public String getCode() {

        return code;
    }

    public void setCode(final String code) {

        this.code = code;
    }

    @Override
    public String getMessage() {

        return message;
    }

    public void setMessage(final String message) {

        this.message = message;
    }

    public Date getTime() {

        return time;
    }

    public void setTime(final Date time) {

        this.time = time;
    }

    @Override
    public T getBody() {

        return body;
    }

    public void setBody(final T body) {

        this.body = body;
    }

}